<?php
//查询队伍数据
$params = json_decode(file_get_contents("php://input"), true);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $nikeName = $params['nikeName'];
}

include('../mysqli_connect.php');
if ($nikeName == '') {
  $sql = "select u.*,t.team_name from team t, user u where t.team_id=u.vote_team";
} else {
  $sql = "select u.*,t.team_name from team t, user u where t.team_id=u.vote_team and (nike_name like '%{$nikeName}%')";
}

$res = mysqli_query($dbc, $sql);
if (!$res) {
  printf("Error: %s\n", mysqli_error($dbc));
  exit();
}
if ($res) {
  // 查询成功
  $resultArray = array();
  $i = 0;
  while ($row = mysqli_fetch_row($res)) {
    // $resultArray[] = $row;
    $resultArray[$i]['userId'] = $row[0];
    $resultArray[$i]['userName'] = $row[1];
    $resultArray[$i]['userPassword'] = $row[2];
    $resultArray[$i]['nikeName'] = $row[3];
    $resultArray[$i]['voteTeam'] = $row[12];
    $resultArray[$i]['gender'] = $row[6];
    $resultArray[$i]['age'] = $row[7];
    $resultArray[$i]['birthday'] = $row[8];
    $resultArray[$i]['phone'] = $row[9];
    $resultArray[$i]['address'] = $row[10];
    $i = $i + 1;
  }
  $response = array('status' => true, 'message' => '查询数据成功', 'data' => $resultArray, 'sql' => $sql);
  echo json_encode($response);
} else {
  $response = array('status' => false, 'message' => '查询队伍失败', 'data' => $resultArray);
  echo json_encode($response);
}
